#ifndef UDP_H
#define UDP_H

#include <QObject>
#include <QUdpSocket>
#include <QNetworkDatagram>
#include <QDebug>
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
#include <QHostAddress>
#include <QHostInfo>
#include <QString>
#include <QPair>

class Udp : public QObject
{
    Q_OBJECT
private:
    static constexpr int Multi_Port = 45454;
    static constexpr int Uni_Port = 45455;

    QUdpSocket *Udp_Multicast;
    QUdpSocket *Udp_Unicast;

    QHostAddress groupAddress;
    QString localhost;

    QByteArray datagram;

public:
    void sendMulticast();
    void sendUnicast(QString host, int port = Uni_Port);
    void setTTL(int newTtl);

private slots:
    void readUnicast();

public:
    explicit Udp(QObject *parent = nullptr);

signals:
    void readJson(QPair<QString, QString> pair);
};

#endif // UDP_H
